<template>
  <base-breadcrumb>
    <a-card
      :bordered="false"
      style="margin-bottom: 20px"
    >
      <title-name title="项目基础信息" />
      <a-form layout="horizontal">
        <a-row :gutter="24">
          <a-col
            :md="16"
            :sm="16"
          >
            <a-form-item
              label="所属单位"
              :label-col="{lg: {span: 5}, sm: {span:5}}"
              :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"
            >
              <BaseInput
                v-model="dels.viewName"
                placeholder=""
                disabled
              />
            </a-form-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-item
              label="项目编号"
              :label-col="{lg: {span: 5}, sm: {span:5}}"
              :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"
            >
              <BaseInput
                v-model="dels.projectNum"
                placeholder=""
                disabled
              />
            </a-form-item>
          </a-col>
<!--          <a-col-->
<!--            :md="8"-->
<!--            :sm="8"-->
<!--          >-->
<!--            <a-form-item-->
<!--              label="分公司"-->
<!--              :label-col="{lg: {span: 5}, sm: {span:5}}"-->
<!--              :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"-->
<!--            >-->
<!--              <BaseInput-->
<!--                v-model="dels.branch"-->
<!--                placeholder=""-->
<!--                disabled-->
<!--              />-->
<!--            </a-form-item>-->
<!--          </a-col>-->
        </a-row>

        <a-row :gutter="24">
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-item
              label="维保期年限(年)"
              :label-col="{lg: {span: 5}, sm: {span:5}}"
              :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"
            >
              <BaseInput
                v-model="dels.maintainYear"
                placeholder=""
                disabled
              />
            </a-form-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-item
              label="维保期截止时间"
              :label-col="{lg: {span: 5}, sm: {span:5}}"
              :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"
            >
              <BaseInput
                v-model="dels.endTime"
                disabled
              />
            </a-form-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-item
              label="状态"
              :label-col="{lg: {span: 5}, sm: {span:5}}"
              :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"
            >
              <BaseInput
                v-model="dels.statusName"
                disabled
              />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false">
      <title-name title="新增维保期记录" />

      <div class="table-operator">
        <a-button
          type="primary"
          icon="plus"
          @click="handleAdd"
        >
          新增记录
        </a-button>
        <a-button @click="handleDelete">
          删除
        </a-button>
      </div>

      <s-table
        ref="table"
        bordered
        :scroll="{x:1500}"
        size="default"
        :row-key="record=>record.id"
        :columns="columns"
        :data="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        :row-selection="rowSelection"
        show-pagination="auto"
      >
        <span
          slot="serial"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>

        <span
          slot="action"
          slot-scope="text, record"
        >
          <template>
            <a @click="recordDetails(record)">查看</a>
          </template>
        </span>
      </s-table>

      <a-modal
        v-model="visible"
        width="900px"
        :title="title"
        destroy-on-close
      >
        <title-name title="基本信息" />
        <template slot="footer">
          <a-button
            key="back"
            @click="handleCancel"
          >
            取消
          </a-button>
          <a-button
            key="submit"
            type="primary"
            :loading="loading"
            @click="handleOk"
          >
            确定新增
          </a-button>
        </template>
        <a-form :model="form">
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="项目名称"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInput
                  v-model="dels.projectName"
                  disabled
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="项目编号"
                :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInput
                  v-model="dels.projectNum"
                  disabled
                />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="项目经理"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInput
                  v-model="dels.projectManager"
                  disabled
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="记录人员"
                :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInput
                  v-model="dels.createName"
                  disabled
                />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="上午天气"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <a-select
                  v-model="form.morningWeather"
                  placeholder="请选择"
                >
                  <a-select-option
                    v-for="item in weathers"
                    :key="item.id"
                    :value="item.id"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="下午天气"
                :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <a-select
                  v-model="form.afterNoonWeather"
                  placeholder="请选择"
                >
                  <a-select-option
                    v-for="item in weathers"
                    :key="item.id"
                    :value="item.id"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="最高温度(˚C)"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInput
                  v-model="form.maxTemperature"
                  placeholder="输入最高温度"
                  @input="checkInput"
                  @blur="maxTemperatures"
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="最低温度(˚C)"
                :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInput
                  v-model="form.minTemperature"
                  placeholder="输入最低温度"
                  @input="checkInputs"
                  @blur="minTemperatures"
                />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="风力"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInput
                  v-model="form.windPower"
                  placeholder="请输入"
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="有无突发事件"
                :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <a-select
                  v-model="form.emergency"
                  placeholder="请选择"
                  @change="isHaveEmergency"
                >
                  <a-select-option value="0">
                    无
                  </a-select-option>
                  <a-select-option value="1">
                    有
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col
              v-if="emergencyInfo"
              :md="24"
              :sm="24"
            >
              <a-form-item
                label="突发事件说明"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseTextarea
                  v-model="form.emergencyInstructions"
                  placeholder="请输入"
                />
              </a-form-item>
            </a-col>
          </a-row>


          <title-name title="维保信息" />
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="维保记录名称"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInput
                  v-model="form.recordName"
                  placeholder="输入维保记录名称"
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="维保费用(万)"
                :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInputNumber
                  v-model="form.maintainCost"
                  :min="0"
                  placeholder="输入维保费用(万)"
                  @keydown="handleInput2"
                />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="维保日期"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInput
                  v-model="currentDate"
                  disabled
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="实施人员"
                :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <a-select
                  v-model="form.implement"
                  allow-clear
                  placeholder="请选择"
                >
                  <a-select-option
                    v-for="item in memberList"
                    :key="item.employeeId"
                    :value="item.employeeId"
                  >
                    {{ item.employeeName }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="实施队伍"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInput
                  v-model="form.implemenTeam"
                  placeholder="输入实施队伍"
                />
              </a-form-item>
            </a-col>
          </a-row>

          <title-name title="维保事项" />
          <div class="table-operator">
            <a-button
              type="primary"
              @click="addLine"
            >
              新增行
            </a-button>
            <a-button
              type=""
              @click="deleteMatters"
            >
              删除
            </a-button>
          </div>
          <a-table
            bordered
            :columns="columnMatter"
            :data-source="matters"
            :row-selection="rowSelections"
            :custom-row="selectRow"
          >
            <span
              slot="serial"
              slot-scope="text, record, index"
            >{{ index + 1 }}</span>
            <template
              slot="descriptions"
              slot-scope="text, record"
            >
              <BaseInput
                :value="text"
                :text="text"
                @change="onCellChangeDes"
              />
            </template>

            <template
              slot="responsible"
              slot-scope="text, record"
            >
              <a-select
                style="width: 100%;"
                :value="record.responsible"
                @change="handleChangeResponsible"
              >
                <a-select-option
                  v-for="item in responsibles"
                  :key="item.id"
                  :value="item.id"
                >
                  {{ item.name }}
                </a-select-option>
              </a-select>
            </template>

            <template
              slot="subcontractorName"
              slot-scope="text, record"
            >
              <BaseInput
                :value="text"
                :text="text"
                @change="onCellChangeSub"
              />
            </template>
          </a-table>

          <title-name
            title="上传相关附件"
            style="margin-top: 20px"
          />
          <u-table
            :list-url="listUrl"
            :upload-list="uploadList"
            :delete-url="deleteUrl"
            business-code="PM15"
            @fileArrysData="fileArrysData"
          />
        </a-form>
      </a-modal>


      <!--维保期记录-->
      <a-modal
        v-model="visibles"
        width="900px"
        :title="'查看维保记录详情'"
        destroy-on-close
      >
        <title-name title="基本信息" />
        <template slot="footer">
          <a-button
            key="back"
            @click="handleCancels"
          >
            取消
          </a-button>
        </template>
        <a-form :model="form">
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="项目名称"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <!-- <a-input v-model="recordsDel.projectName" disabled/> -->
                <a-textarea
                  v-model="recordsDel.projectName"
                  class="distextarea"
                  disabled
                  auto-size
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="项目编号"
                :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <!-- <a-input v-model="recordsDel.projectCode"   disabled/> -->
                <a-textarea
                  v-model="recordsDel.projectCode"
                  class="distextarea"
                  disabled
                  auto-size
                />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="项目经理"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <!-- <a-input v-model="recordsDel.pmName" disabled/> -->
                <a-textarea
                  v-model="recordsDel.pmName"
                  class="distextarea"
                  disabled
                  auto-size
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="记录人员"
                :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <!-- <a-input v-model="recordsDel.creatorName" disabled/> -->
                <a-textarea
                  v-model="recordsDel.creatorName"
                  class="distextarea"
                  disabled
                  auto-size
                />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="上午天气"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <a-input
                  v-model="recordsDel.morningWeatherName"
                  disabled
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="下午天气"
                :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <a-input
                  v-model="recordsDel.afterNoonWeatherName"
                  disabled
                />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="最高温度(˚C)"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <a-input
                  v-model="recordsDel.maxTemperature"
                  disabled
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="最低温度(˚C)"
                :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <a-input
                  v-model="recordsDel.minTemperature"
                  disabled
                />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="风力"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <a-textarea
                  v-model="recordsDel.windPower"
                  class="distextarea"
                  disabled
                  auto-size
                />
                <!-- <a-input v-model="recordsDel.windPower"   disabled /> -->
              </a-form-item>
            </a-col>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="有无突发事件"
                :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <a-input
                  v-model="recordsDel.emergency"
                  disabled
                />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col
              v-if="emergencyInfo"
              :md="24"
              :sm="24"
            >
              <a-form-item
                label="突发事件说明"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseTextarea
                  v-model="recordsDel.emergencyInstructions"
                  disabled
                />
              </a-form-item>
            </a-col>
          </a-row>


          <title-name title="维保信息" />
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="维保记录名称"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <!-- <a-input v-model="recordsDel.recordName" disabled/> -->
                <a-textarea
                  v-model="recordsDel.recordName"
                  class="distextarea"
                  disabled
                  auto-size
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="维保费用(万)"
                :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <a-input
                  v-model="recordsDel.maintainCost"
                  disabled
                />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="维保日期"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <a-input
                  v-model="recordsDel.maintainTime"
                  disabled
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="实施人员"
                :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <a-input
                  v-model="recordsDel.implementName"
                  disabled
                />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="实施队伍"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <!-- <a-input v-model="recordsDel.implemenTeam" disabled  /> -->
                <a-textarea
                  v-model="recordsDel.implemenTeam"
                  class="distextarea"
                  disabled
                  auto-size
                />
              </a-form-item>
            </a-col>
          </a-row>

          <title-name title="维保事项" />
          <a-table
            bordered
            :columns="columnMatter"
            :data-source="recordsDel.matters"
          >
            <span
              slot="serial"
              slot-scope="text, record, index"
            >{{ index + 1 }}</span>
          </a-table>

          <title-name
            title="上传相关附件"
            style="margin-top: 20px"
          />
          <u-table
            :is-show="false"
            :upload-arrys="recordsDel.fileIdList"
            :list-url="listUrl"
            :upload-list="uploadList"
            :delete-url="deleteUrl"
          />
        </a-form>
      </a-modal>
    </a-card>

    <div class="footer-btns page-btn-right-top">
      <a-button
        type="primary"
        style="float: right"
        @click="goBack"
      >
        关闭
      </a-button>
    </div>
  </base-breadcrumb>
</template>

<script>
  import { STable } from '@/components'
  import { getMaintainRecordList, addMaintainRecord, getMaintainDels,deleteMaintainRecord ,maintainOneDeatails   } from '@/api/project/maintain'
  import  {  getOrganizeUserList, getTypes ,getLabelTypes} from '@/api/commons'

  import ARow from 'ant-design-vue/es/grid/Row'


  const columns = [
    {
      title: '序号',
       width: 65,
      scopedSlots: { customRender: 'serial' }
    },
    {
      title: '维保记录名称',
      dataIndex: 'recordName'
    },
    {
      title: '有无突发事件',
      dataIndex: 'emergency',

    },
    {
      title: '实施人员',
      dataIndex: 'implement',
    },
    {
      title: '实施队伍',
      dataIndex: 'implemenTeam',
    },
    {
      title: '维保费用(万)',
      dataIndex: 'maintainCost',
    },
    {
      title: '创建人',
      dataIndex: 'creatorName',
    },
    {
      title: '维保时间',
      dataIndex: 'maintainTime',
    },
    {
      title: '操作',
      dataIndex: 'action',
      width: '150px',
      fixed:'right',
      scopedSlots: { customRender: 'action' }
    }
  ]

  const columnMatter = [
    {
      title: '序号',
       width: 65,
      dataIndex: 'serial',
      scopedSlots: { customRender: 'serial' },
    },
    {
      title: '维保事项描述',
      dataIndex: 'descriptions',
      width: '20%',
      scopedSlots: { customRender: 'descriptions' },
    },
    {
      title: '责任方',
      dataIndex: 'responsible',
      width: '20%',
      scopedSlots: { customRender: 'responsible' },
    },
    {
      title: '责任为分包商时,分包商名称',
      dataIndex: 'subcontractorName',
      width: '40%',
      scopedSlots: { customRender: 'subcontractorName' },
    }
  ];

  export default {
    name:'a'+Date.now(),
    components: {
      ARow,
      STable,
    },
    data() {
      return {
        emergencyInfo:false, // 突发事件说明
        columns,
        columnMatter,
        loading:false,

        listUrl:'',
        deleteUrl:'/cscec-project-business/file/business/project-fileDelete',
        uploadList:'/cscec-project-business/file/business/fileUpload',

        matters:[
          {key:0,descriptions:'',responsible:'',subcontractorName:''}
        ],

        visible:false,
        visibles:false,
        title:'',
        form:{
          maxTemperature:null,
          minTemperature:null
        },

        currentDate:'', // 当前日期

        responsibles:[],

        queryParam:{
          projectId:(JSON.parse(this.$route.query.obj)).projectId
        },
        data:[],
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          this.queryParam.projectId = (JSON.parse(this.$route.query.obj)).projectId
          const requestParameters = Object.assign({}, parameter, this.queryParam)
          return getMaintainRecordList(requestParameters)
            .then(res => {
              return res
            })
        },
        selectedRowKeys: [],
        selectedRows: [],
        selectId:[],

        selectedRowKeysM: [],
        selectedRowsM: [],
        selectMaters:[],
        count:1,

        recordsDel:{}, // 维保记录查看详情
        dels:{
          viewName: ""
        },  // 详情数据
        totalDels:{},
        memberList:[], // 实施人员

        weathers:[],  // 天气数据

      }
    },

    created() {
        this.dels = JSON.parse(this.$route.query.obj)
        this.dels.viewName = this.dels.branch + '/' + this.dels.projectName
        this.dels.createName =  JSON.parse(sessionStorage.getItem('ycloud-user_info')).name
        this.matters[0] = this.selectedRowsM
        this.getCurrentDate()  // 获取当前日期

    },
    computed: {
      rowSelection() {
        return {
          selectedRowKeys: this.selectedRowKeys,
          selectedRows: this.selectedRows,   // 当前行所有数据
          onChange: this.onSelectChange
        }
      },
      rowSelections(){
        return {
          selectedRowKeysM: this.selectedRowKeysM,
          selectedRowsM: this.selectedRowsM,   // 当前行所有数据
          onChange: this.onSelectChanges
        }
      },
    },
    methods: {
      // 维保期记录详情
      recordDetails(val){
        maintainOneDeatails({id:val.id}).then(res=>{
          if(res.code == 200 || res.data.code == 200){
            this.visibles = true
            this.recordsDel = res.data
          }
        })
      },


      handleInput2(e) {
        // 通过正则过滤小数点后两位
        e.target.value = (e.target.value.match(/^\d*(\.?\d{0,1})/g)[0]) || null
      },
      checkInput() {
        this.form.maxTemperature = this.dealInputVal(this.form.maxTemperature);
      },
      checkInputs() {
        this.form.minTemperature = this.dealInputVal(this.form.minTemperature);
      },
      dealInputVal(value) {
        // value = value.replace(/^0*(0\.|[1-9])/, "$1");
        // // value = value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
        // // value = value.replace(/^\./g, ""); //验证第一个字符是数字而不是字符
        // value = value.replace(/\.{1,}/g, "."); //只保留第一个.清除多余的
        // value = value.replace(".", "$#$").replace("$#$", ".");
        // value = value.replace(/^(\-)*(\d*)\.(\d\d).*$/, "$1$2.$3"); //只能输入两个小数
        // value = value.indexOf(".") > 0 ? value.split(".")[0].substring(0, 5) + "." + value.split(".")[1] : value.substring(0, 5);
        //
        // if (t == '-') {
        //   obj.value = '-' + obj.value;
        // }

        var t = value.charAt(0);
        //先把非数字的都替换掉，除了数字和.
        value = value.replace(/[^\d.]/g, "");
        //必须保证第一个为数字而不是.
        value = value.replace(/^\./g, "");
        //保证只有出现一个.而没有多个.
        value = value.replace(/\.{2,}/g, ".");
        //保证.只出现一次，而不能出现两次以上
        value = value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        value = value.replace(/^(\-)*(\d*)\.(\d\d).*$/, "$1$2.$3");
        value = value.indexOf(".") > 0 ? value.split(".")[0].substring(0, 5) + "." + value.split(".")[1] : value.substring(0, 5);
        //如果第一位是负号，则允许添加   如果不允许添加负号 可以把这块注释掉
        if (t == '-') {
         value = '-' + value;
        }


        return value;
      },

      // 最高温度
      minTemperatures(e){
        let minTem = e.target.value
        if(this.form.maxTemperature && ( parseFloat(this.form.maxTemperature) < parseFloat(minTem))){
          this.form.minTemperature = null
          this.$message.error("最低温度不能高于最高温度！")
          return;
        }
      },

      // 最低温度
      maxTemperatures(e){
        let maxTem = e.target.value
        if(this.form.minTemperature && ( parseFloat(maxTem) < parseFloat(this.form.minTemperature))){
          this.form.maxTemperature = null
          this.$message.error("最高温度不能低于最低温度！")
          return;
        }
      },
      isHaveEmergency(val){
        if(val == '1'){
          this.emergencyInfo = true
        }else{
          this.emergencyInfo = false
        }
      },
      goBack() {
        this.$multiTab.close(this.$route.fullpath)
      },
      fileArrysData(val){
        this.form.fileIdList = val
      },
      getImplees(){
        getOrganizeUserList({id:this.dels.projectId}).then(res=>{
          this.memberList = res.data
        })
      },
      getCurrentDate(){
        var d1 = new Date()
        var year = d1.getFullYear();//年
        var month = d1.getMonth() + 1;//月
        var day = d1.getDate();//日

        if (month < 10) {
          month = "0" + month;
        }
        if (day < 10) {
          day = "0" + day;
        }
        this.currentDate = year + "-"+month+"-"+day
        this.form.maintainTime = this.currentDate

      },
      search(){
        this.$refs.table.refresh(true)
      },

      addLine(){
        const { count, matters } = this;
        const newData = {
          key:  count,
          descriptions: '',
          responsible: '',
          subcontractorName: '',
        };
        this.matters = [...matters, newData];
        this.count = count + 1;

      },

      selectRow(record){
        return {
          on: {
            click: () => {
              this.selectedRowsM = record   // 当前行数据
            }
          }
        }
      },


      handleAdd(){
        this.visible = true
        this.title='新增维保记录'
        this.form = {}
        this.matters = []
        this.emergencyInfo = false
        this.getImplees()
        this.getTypes()
      },
      getTypes(){
        let that = this
        getTypes({type:19}).then(res=>{
          that.weathers = res.data
        })
        getTypes({type:20}).then(res=>{
          this.responsibles = res.data
        })
      },

      handleCancel(){
        this.visible = false
      },
      handleCancels(){
        this.visibles = false
      },
      onCellChangeDes(val){
        this.selectedRowsM.descriptions = val.target.value
      },

      handleChangeResponsible(val){
        this.selectedRowsM.responsible = val
      },

      onCellChangeSub(val){
        this.selectedRowsM.subcontractorName = val.target.value
      },

      handleOk(){
        let that = this;
        if(that.loading){
          return
        }
        if(that.form.id){

        }else{

          if( parseFloat(that.form.maxTemperature) < parseFloat(that.form.minTemperature)){
            that.$message.error("最高温度不能低于最低温度！")
            return;
          }

          if(that.matters.length > 0) {
            try {
              that.matters.forEach(function(obj, i) {
                if ((obj.descriptions == '' || obj.responsible == '') || (obj.responsible == '665811356942999552' && obj.subcontractorName == '')) {
                  throw new Error('mandatoryMessage')
                }

              })
            }catch(e){
              console.log("fhksa:",e.message)
               if(e.message == 'mandatoryMessage'){
                 that.$message.error("维保事项和分包商不能为空,当责任方为分包商时，分包商名称不能为空!")
                 return;
               }

            }
          }



          that.form.matters = that.matters
          that.form.projectId = that.dels.projectId
          that.loading = true
          addMaintainRecord(that.form).then((res)=>{
            if(res.code == 200){
              that.loading = false
              that.$message.success("新增成功")
              that.visible = false
              that.$refs.table.refresh(true)
            }
          }).catch(() => {
            that.loading = false
          })
        }
      },
      onSelectChange(selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
        let ids = []
        this.selectedRows.forEach((item)=>{
           ids.push(item.id)
        })
        this.selectId = ids

      },

      onSelectChanges(selectedRowKeysM, selectedRowsM){
        this.selectedRowsM = selectedRowsM
      },

      handleDelete(){
        let _this = this
         if(_this.selectedRowKeys.length == 0){
           _this.$message.error("请先选择需要删除的维保期记录！")
           return
         }
        _this.$confirm({
          title: '警告提醒！',
          content: '确定删除？',
          okType: 'danger',
          onOk() {

            deleteMaintainRecord({recordIds:_this.selectId,projectId:_this.dels.projectId}).then((res)=>{
              if(res.data.code == 200){
                _this.$message.success("删除成功")
                _this.$refs.table.refresh(true)
                _this.selectedRowKeys = []
              }
            })
          },
          onCancel() {
            console.log('Cancel');
          },
        });
      },

      deleteMatters(){
        let _this = this
        if(_this.selectedRowsM.length == 0 || _this.selectedRowsM.length == undefined){
          _this.$message.error("请先选择需要删除的维保事项！")
          return
        }

        _this.$confirm({
          title: '警告提醒！',
          content: '确定删除选中维保事项？',
          okType: 'danger',
          onOk() {

            let arr1 =  _this.selectedRowsM
            let arr2 =  _this.matters

            let add = arr2.filter(item=>!arr1.some(ele=>ele.key === item.key))

            _this.matters = add
            _this.selectedRowsM = []

            _this.$message.success("删除成功！")

          },
          onCancel() {
            console.log('Cancel');
          },
        });
      },

    }
  }
</script>
<style>
  .distextarea {
    resize: none;
    margin: 0;
  }
</style>
